﻿function QuickHelp()
{
}

QuickHelp.Items = [];
QuickHelp.Positions = ["ArrowDownLeft", "ArrowDownRight", "ArrowTopLeft", "ArrowTopRight"];
QuickHelp.Add = function(helpItem)
{
    this.Items.push(helpItem);
};

QuickHelp.Init = function()
{
    for( var i=0; i<this.Items.length; ++i )
    {
        var item = this.Items[i];
        item.Show();
    }
};

function HelpItem(parentElement, objElement, text, topOffset, leftOffset, width, position)
{
    this.PElement = parentElement;
    this.OElement = objElement;
    this.Text = text;
    this.TopOffset = topOffset ? topOffset : 0;
    this.LeftOffset = leftOffset ? leftOffset : 0;
    this.Width = width ? width : 0;
    this.Position = position
};

HelpItem.prototype.Show = function()
{
        var otop = this.OElement.offsetTop;
        var oleft = this.OElement.offsetLeft;
        var pos = QuickHelp.Positions[this.Position];
        var div = document.createElement("DIV");
        this.Element = div;
        this.PElement.appendChild(div);
        div.className = "QuickHelp";
        
        with(div.style)
        {
            left = oleft + this.LeftOffset + "px";
            width = this.Width + "px";
        }            
        
        var arrow = document.createElement("DIV");
        div.appendChild(arrow);
        arrow.className = pos;
        arrow.innerHTML = "&nbsp;";
       
        var textDiv = document.createElement("DIV");
        div.appendChild(textDiv);
        textDiv.className = this.IsArrowDown(pos) ? "TextDown" : "TextUp";
        
        textDiv.onmouseover = function()
        {
            if( !this.closeObj )
            {
                var closeBtn = document.createElement("IMG");
                textDiv.appendChild(closeBtn);
                closeBtn.src = "/images/QuickHelp/helpclose.jpg";
                closeBtn.style.position = "absolute";
                closeBtn.style.right = "3px";
                closeBtn.style.top = "3px";    
                closeBtn.Object = this;
                closeBtn.title = "单击关闭该提示";
                
                closeBtn.onclick = function()
                {
                    this.Object.parentNode.style.display = "none";
                };
                
                this.closeObj = closeBtn;           
            }
            this.closeObj.style.display = '';
        };
        
        textDiv.onmouseout = function()
        {
            this.closeObj.style.display = 'none';
        };
        
        textDiv.innerHTML = this.Text;    
        
        var top = "";
        var offset = 15;
        typeof(window.event) == "object" ? offset = 5 : offset = 5;
        if( this.IsArrowDown(pos) )
        {
            top = otop - div.offsetHeight + this.OElement.offsetHeight - offset + this.TopOffset + "px"
        }
        else
        {
            top = otop + div.offsetHeight + this.OElement.offsetHeight + offset + this.TopOffset + "px"
        }
        
        div.style.top = top;
        window.setTimeout(this.CloseHelp, 20000, this.Element);
};

HelpItem.prototype.IsArrowDown = function(pos)
{
    return pos == QuickHelp.Positions[0] || pos == QuickHelp.Positions[1];
}

HelpItem.prototype.CloseHelp = function(e)
{
    e.style.display = "none";
};


var _st = window.setTimeout;

window.setTimeout = function(fRef, mDelay) 
{
    try
    {
        if(typeof fRef == 'function')
        {
            var argu = Array.prototype.slice.call(arguments,2);
            var f = (function()
            { 
                fRef.apply(null, argu); 
            });
            
            return _st(f, mDelay);
        }
        return _st(fRef,mDelay);
    }
    catch(e)
    {}
};